package cn.lingyangwl.agile.system.model.rqrs.user;

import cn.lingyangwl.agile.model.constants.ValidationCons;
import cn.lingyangwl.agile.model.constants.UserCons;
import cn.lingyangwl.framework.tool.core.StringUtils;
import cn.lingyangwl.framework.tool.core.exception.BizException;
import io.swagger.annotations.ApiModelProperty;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;

import javax.validation.constraints.NotNull;

/**
 * 编辑用户
 * @author shenguangyang
 */
@Getter
@Setter
@ToString
public class UserUpdateReq extends UserBase {
    @ApiModelProperty(value = "选择的角色ids, 逗号分割")
    private String roleIds;

    /** 选择的部门 */
    @ApiModelProperty(value = "选择的部门ids, 逗号分割")
    private String deptIds;

    @NotNull(message = ValidationCons.NOT_EMPTY)
    private Long id;

    public String getRoleIds() {
        boolean ret = StringUtils.toList(roleIds, ",", Long.class).stream().
                anyMatch(e -> e.compareTo(UserCons.Role.ADMIN_ID) <= 0);
        if (ret) {
            throw new BizException("角色id必须大于1");
        }
        return roleIds;
    }
}
